<?php

if($_GET['_a']==2)
{
	$id = $_GET['_d'];
	$page = $_GET['page'];
	$st = $_REQUEST['_st'];
		
	$id = $_REQUEST['_d'];
	
	$q = mysql_fetch_array(mysql_query("select upload_file  from right_ad where id='$id'"));
	$path = "../uploads/".$q["upload_file"];
	@unlink($path);
		
	mysql_query("delete from right_ad where id='$id'");
	
	//header("location:index.php?tc=picture&_st=$st&page=$page&_s=2");
	echo "<script>window.location='index.php?tc=view_right_ads&_st=$st&page=$page&_s=2'</script>";
	exit;
}

?>
<script language="javascript" type="text/javascript">
function show()
{
	document.ppf.action="index.php?tc=gadget_add";
	document.ppf.submit();
}
</script>
<form name="ppf" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">Right Ads</span>&nbsp;
	
	</td>
    <td width="80%" align="right" class="font12">
    <a href="index.php?tc=add_right_ads" class="font12">Add Image</a>  
    <!--<a href="index.php?tc=addcity" class="font12">Add City</a>-->
    </td>
	<td align="right">
    		    
    </td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="2" height="11"></td>
</tr>    
</table>
</form>    
	
	<?php
if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
if($_REQUEST['_s'] == 2)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Deleted Successfully</div></td>
    </tr>    
    </table>
<?php } ?>

<table width="100%" align="center" border="0" class="list">
<thead>
<tr class="headings">
	<td align="center" width="30">#</td>
    
	<td align="center" width="150">Page Name</td>
    <td align="center">Url</td>
     <td align="center">Image</td>
     <td align="center" width="50">Status</td>
    <td align="center">Actions</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=view_right_ads&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];

if($st == "" || $st == 2)
{
	$res = mysql_query("select id from right_ad");
	
	$query = mysql_query("select r.id id,r.posttion, r.page_id, r.upload_file, r.url, r.active_status,p.page_name  from right_ad r inner join page p on r.page_id=p.id order by id desc limit $offset , $rowsPerPage") or die(mysql_error());
}
else
{
	if($st == 3) $st=0;
	$res = mysql_query("select id from right_ad where active_status='$st'");
	
	$query = mysql_query("select * from right_ad where active_status='$st' order by id desc limit $offset , $rowsPerPage");
}
$i = 1;
while($q = mysql_fetch_array($query))
{ 
	if($q["active_status"] == 1) $status = "Approved";
	else $status = "Pending";
	?>
    <tr class="font12">
        <td align="center"><?php echo $i+$offset;?></td>
        <td align="left"><?php echo $q["page_name"];?></td>
       
          <td align="left"><?php echo substr($q["url"],0,50);?></td>	
           <td align="center"><img src="thumb.php?file=../uploads/<?php echo ''.$q["upload_file"];?>" width="50px" /></td>
        <td align="center"><?php echo $status;?></td>
        <td align="center">
        	<a href="index.php?tc=up_right_ads&_d=<?php echo $q['id'];?>&page=<?php echo $pageNum;?>&_st=<?php echo 
			$_REQUEST['_st'];?>" class="font12">Edit</a>&nbsp;|
            <a href="index.php?tc=view_right_ads&_d=<?php echo $q['id'];?>&page=<?php echo $pageNum;?>&_a=2&_st=<?php echo $_REQUEST['_st'];?>" onClick="return confirm('Are you sure want to delete?');" class="font12">Delete</a>
        </td>
   	</tr>     
<?php 
	$i++;
	$imid++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="7" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>      